<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<t:base type="jquery,easyui,tools,DatePicker"></t:base>
<div class="easyui-layout" fit="true">
  <div region="center" style="padding:0px;border:0px">
  <t:datagrid name="tKpOrderList" autoLoadData="true" extendParams="view: detailview,detailFormatter:detailFormatterFun,onExpandRow: onExpandRowFun" sortName="id" sortOrder="desc" checkbox="true" fitColumns="true" title="打印" actionUrl="tKpOrderController.do?datagrid&orderType=正常销售" idField="id" fit="true" queryMode="group">
   <t:dgCol title="操作" field="opt" width="100"></t:dgCol>


   <t:dgCol title="订单号"  field="id"  hidden="true"   queryMode="single"  width="80"></t:dgCol>
   <t:dgCol title="流水号"  field="by5"  query="true"  queryMode="single"  width="100"></t:dgCol>

   <t:dgCol title="创建人名称"  field="createName"  hidden="true"  queryMode="single"  width="120"></t:dgCol>

   <t:dgCol title="更新人名称"  field="updateName"  hidden="true"  queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="更新人登录名称"  field="updateBy"  hidden="true"  queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="更新日期"  field="updateDate"  formatter="yyyy-MM-dd"  hidden="true"  queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="所属部门"  field="sysOrgCode"  hidden="true"  queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="所属公司"  field="sysCompanyCode"  hidden="true"  queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="流程状态"  field="bpmStatus"  hidden="true"  queryMode="single"  dictionary="bpm_status"  width="120"></t:dgCol>
   <%--<t:dgCol title="客户编码"  field="cusCode"  query="true"  queryMode="single"  dictionary="pop_kp_cus,cusCode,cusName,cus_code,cus_name"  popup="true"  width="120"></t:dgCol>--%>
   <%--<t:dgCol title="客户名称"  field="cusName"  query="true"  queryMode="single"  width="120"></t:dgCol>--%>
   <%--<t:dgCol title="工地编码"  field="gdCode"  query="true"  queryMode="single"  dictionary="pop_kp_gongdi,gdCode,gdName,gd_code,gd_name"  popup="true"  width="120"></t:dgCol>--%>
   <%--<t:dgCol title="工地名称"  field="gdName"  query="true"  queryMode="single"  width="120"></t:dgCol>--%>
   <t:dgCol title="客户名称"  field="cusCode"  query="true"  queryMode="single" dictionary="t_kp_cus,cus_code,cus_name" width="120"></t:dgCol>
   <%--<t:dgCol title="工地编码"  field="gdCode"  query="true"  queryMode="single"  dictionary="pop_kp_gongdi,gdCode,gdName,gd_code,gd_name"  popup="true"  width="120"></t:dgCol>--%>
   <t:dgCol title="承建单位"  field="gdCode"  query="true" dictionary="t_kp_gongdi,gd_code,gd_name"    queryMode="single"  width="220"></t:dgCol>

   <%--<t:dgCol title="司机"  field="ysSiji"  query="true"  queryMode="single"  width="120"></t:dgCol>--%>
   <%--<t:dgCol title="车号"  field="ysChehao"  query="true"  queryMode="single"  width="120"></t:dgCol>--%>
   <%--<t:dgCol title="联系人"  field="ysLianxiren"  query="true"  queryMode="single"  width="120"></t:dgCol>--%>
   <t:dgCol title="总价值"  field="orAmount"  queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="备注"  field="orRemark"  queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="订单类型"  field="orderType"   extendParams="styler:fmtypet"    queryMode="single"  dictionary="order_type"  width="120"></t:dgCol>

   <t:dgCol title="备用1"  field="by1"  hidden="true"  queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="备用2"  field="by2"  hidden="true"  queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="备用3"  field="by3"  hidden="true"  queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="备用4"  field="by4"  hidden="true"  queryMode="single"  width="120"></t:dgCol>
   <%--<t:dgCol title="备用5"  field="by5"  hidden="true"  queryMode="single"  width="120"></t:dgCol>--%>
   <t:dgCol title="订单状态"  field="orStatus"  queryMode="single"  dictionary="or_status"  width="120"></t:dgCol>
   <t:dgCol title="开票人"  field="createBy"     queryMode="single"  width="80"></t:dgCol>
   <t:dgCol title="开票日期"  field="createDate"  formatter="yyyy-MM-dd"   queryMode="single"  width="90"></t:dgCol>
   <%--<t:dgCol title="操作" field="opt" width="100"></t:dgCol>--%>
   <t:dgFunOpt title="打印" funname="doprint(id)"  urlclass="ace_button"   exp="orStatus#ne#已提交"   />
   <%--exp="orStatus#eq#已开票"--%>
   <%--<t:dgDelOpt title="删除" url="tKpOrderController.do?doDel&id={id}"  urlclass="ace_button" urlfont="fa-trash-o"/>--%>
   <%--<t:dgToolBar title="正常销售" icon="icon-add" url="tKpOrderController.do?goAdd&orderType=正常销售"  funname="myadd1" width="100%" height="100%"></t:dgToolBar>--%>
   <%--<t:dgToolBar title="赊销销售" icon="icon-add" url="tKpOrderController.do?goAdd&orderType=赊销销售"  funname="myadd2" width="100%" height="100%"></t:dgToolBar>--%>
   <%--<t:dgToolBar title="损耗补偿" icon="icon-add" url="tKpOrderController.do?goAdd&orderType=损耗补偿"  funname="myadd3" width="100%" height="100%"></t:dgToolBar>--%>

   <%--<t:dgToolBar title="编辑" icon="icon-edit" url="tKpOrderController.do?goUpdate" funname="update" width="100%" height="100%"></t:dgToolBar>--%>
   <%--<t:dgToolBar title="批量删除"  icon="icon-remove" url="tKpOrderController.do?doBatchDel" funname="deleteALLSelect"></t:dgToolBar>--%>
   <t:dgToolBar title="查看" icon="icon-search" url="tKpOrderController.do?goUpdate" funname="detail" width="100%" height="100%"></t:dgToolBar>
   <%--<t:dgToolBar title="导入" icon="icon-put" funname="ImportXls"></t:dgToolBar>--%>
   <%--<t:dgToolBar title="导出" icon="icon-putout" funname="ExportXls"></t:dgToolBar>--%>
   <%--<t:dgToolBar title="模板下载" icon="icon-putout" funname="ExportXlsByT"></t:dgToolBar>--%>
  </t:datagrid>
  </div>
 </div>
 <script src = "webpage/com/yserp/kpyw/tKpOrderList.js"></script>
<script src="plug-in/easyui/extends/datagrid-detailview_new.js"></script>

 <script type="text/javascript">
     function doprint(id){
         var url = "tKpOrderController.do?doPrint&id="+id;
         createdetailwindow("开票打印", url, 800, 400);

         // window.open(url);
     }

     // function doprint(id){
     //     var url = "tKpYushouController.do?doPrint&id="+id;
     //
     //     createdetailwindow("收款打印", url, 800, 400);
     //
     // }
     function fmtypet(val,row,index){

         var s1 = 'background-color:#FF1821;color:#070504;';
         var s2 = 'background-color:#03A89E;color:#070504;';
         // var s2 = 'background-color:#3a87ad;color:#FFF;';
         var s3 = 'background-color:#B0171F;color:#070504;';
         var s4 = 'background-color:#2DFF2A;color:#070504;';
         if (val =='赊销销售') {
             return s1
         }

         if (val =='损耗补偿') {
             return s3
         }
         if (val =='正常销售') {
             return s4
         }
     }
function myadd1(){

    var selectcusValue = $("select[name='cusCode']").val();
    var selectgdValue = $("select[name='gdCode']").val();
    if(selectcusValue==""||selectgdValue==""){
        alert("请选择客户或工地");
    }else{
        SelectgdChange();
        createwindow("正常销售","tKpOrderController.do?goAdd&orderType=正常销售","80%","80%");
    }


}
     function myadd2(){

         var selectcusValue = $("select[name='cusCode']").val();
         var selectgdValue = $("select[name='gdCode']").val();
         if(selectcusValue==""||selectgdValue==""){
             alert("请选择客户或工地");
         }else{
             SelectgdChange();
             createwindow("正常销售","tKpOrderController.do?goAdd&orderType=赊销销售","80%","80%");
         }


     }
     function myadd3(){

         var selectcusValue = $("select[name='cusCode']").val();
         var selectgdValue = $("select[name='gdCode']").val();
         if(selectcusValue==""||selectgdValue==""){
             alert("请选择客户或工地");
         }else{
             SelectgdChange();
             createwindow("正常销售","tKpOrderController.do?goAdd&orderType=损耗补偿","80%","80%");
         }


     }

     $(document).ready(function(){
         //绑定下拉框change事件，当下来框改变时调用 SelectChange()方法
         $("select[name='cusCode']").change(function() { SelectChange(); });
         $("select[name='gdCode']").change(function() { SelectgdChange(); });

     })

function SelectgdChange() {
    var selectcusValue = $("select[name='cusCode']").val();
    var selectgdValue = $("select[name='gdCode']").val();
//加载工地
    var url = "tKpOrderController.do?setvalue&LcusCode="+selectcusValue+"&LgdCode="+selectgdValue;
    $.ajax({
        url:url,
        type:"GET",
        dataType:"JSON",
        async: false,
        success:function(data){
            if(data.success){
                $('#tKpOrderList').datagrid('reload',{});

            }
        }
    });

}
     function SelectChange() {

         //获取下拉框选中项的text属性值

         var selectText = $("select[name='cusCode']").find("option:selected").text();



         //获取下拉框选中项的value属性值

         var selectValue = $("select[name='cusCode']").val();

         console.log(selectValue);

         $("select[name='gdCode']").find("option").remove();


         //加载工地
         var url = "tKpGongdiController.do?getGongdiList&cusCode="+selectValue;
         $.ajax({
             url:url,
             type:"GET",
             dataType:"JSON",
             async: false,
             success:function(data){
                 if(data.success){
                     var gongdiList = data.attributes.gongdiList;
                     if(gongdiList.length > 0){
                         for(var i=0;i<gongdiList.length;i++){
                             var value = gongdiList[i].value;
                             var text = gongdiList[i].text;

                             $("select[name='gdCode']").append("<option value='"+value+"'>"+text+"</option>");
                         }
                     }

                 }
             }
         });

     }


//导入
function ImportXls() {
	openuploadwin('Excel导入', 'tKpOrderController.do?upload', "tKpOrderList");
}

//导出
function ExportXls() {
	JeecgExcelExport("tKpOrderController.do?exportXls","tKpOrderList");
}

//模板下载
function ExportXlsByT() {
	JeecgExcelExport("tKpOrderController.do?exportXlsByT","tKpOrderList");
}

     //返回行明细内容的格式化函数。
     function detailFormatterFun() {
         var s = '<div class="orderInfoHidden" style="padding:-15px;">'
             + '		<div class="easyui-tabs" style="height:120px;width:800px;">'
             + '			<div title="订单明细" style="padding:2px;">'
             + '				<table class="jfrom_order_linetablelines" ></table>'
             + '			</div>'
             + '		</div>'
             + '	</div>';
         return s;
     }
     //当展开一行时触发
     function onExpandRowFun(index, row) {
         //把加上的子表tabs和datagrid初始化
         var tabs = $(this).datagrid('getRowDetail', index).find('div.easyui-tabs');
         tabs.tabs();
         var jfrom_order_linetablelines = $(this).datagrid('getRowDetail', index).find('table.jfrom_order_linetablelines');
         var jfrom_order_linedurl = 'tKpOrderController.do?jfromOrderLineDatagrid&field=cpName,cpGuige,cpDengji,cpJifei,orQty,cpTiji,cpJiage,orAmount&kpId=' + row.id;
         jfrom_order_linetablelines.datagrid({
             singleSelect: true,
             loadMsg: '正在加载',
             fitColumns: true,
             height: '70',
             pageSize: true,
             pageList: [50, 150, 200, 250, 300],
             border: false,
             url: jfrom_order_linedurl,
             idField: 'id',
             rownumbers: true,
             pagination: false,
             columns: [[{
                 title: '产品名称',
                 field: 'cpName',
                 align: 'left',
                 width: 50
             },
                 {
                     title: '规格',
                     field: 'cpGuige',
                     align: 'left',
                     width: 50
                 },
                 {
                     title: '等级',
                     field: 'cpDengji',
                     align: 'left',
                     width: 50
                 },
                 {
                     title: '单位',
                     field: 'cpJifei',
                     align: 'left',
                     width: 50
                 },

                 {
                     title: '块数',
                     field: 'orQty',
                     align: 'left',
                     width: 50
                 },
                 {
                     title: '方量',
                     field: 'cpTiji',
                     align: 'left',
                     width: 50
                 },
                 {
                     title: '单价',
                     field: 'cpJiage',
                     align: 'left',
                     width: 50
                 },
                 {
                     title: '总价',
                     field: 'orAmount',
                     align: 'left',
                     width: 50
                 }]]
         });
     }

 </script>